from tkinter import *
import os
import requests


'''
此模块提供本机出口公网IP查询
'''

class localip():
    def __init__(self):
        pass

    def windowsfive(self,root):
        w = Toplevel(root)
        w.title('公网出口IP地址查询')
        w.geometry('400x200')
        w.geometry('+600+400')
        w.maxsize(width='400',height='200')

        l1 = Label(w,text='公网出口IP地址查询',font='5')
        l1.grid(row=1,column=1,padx=5,pady=5)

        l2 = Label(w,text='结果',font='5',bg='yellow')
        l2.grid(row=3,column=1,padx=5,pady=5)

        b1 = Button(w,text='开始',font='5',bg='red',command=five.getresult)
        b1.grid(row=2,column=1,padx=5,pady=5)

        # b2 = Button(w,text='退出',font='5',bg='red',command=quit)
        # b2.grid(row=2,column=2,padx=5,pady=5)

        self.var = StringVar()
        e = Entry(w,textvariable=self.var)
        e.grid(row=3,column=2,padx=5,pady=5)

        w.mainloop()

    def getresult(self):
        api = 'http://members.3322.org/dyndns/getips'
        response = requests.get(api).text
        print(response)
        self.var.set(response)


#类实例化
five = localip()

#单独执行此文件时，将#号去掉即可
#five.windowsfive()


